From ad111d3113ce0a8893942a30756f10fbe8d9f80c Mon Sep 17 00:00:00 2001
From: Gert Hulselmans <hulselmansgert@gmail.com>
Date: Thu, 11 Nov 2021 22:43:04 +0100
Subject: [PATCH] Update "rand" to 0.8 and "rand_distr" to 0.4. (#1713)

This cherry-picks a commit ad111d3113ce0a8893942a30756f10fbe8d9f80c
from upstream, adjusted to apply to the polars-core tarball from crates.io,
and with the changes to Cargo.lock and Cargo.toml useless for Guix dropped.
This way, we don't have to keep the old rust-rand around.

---
 .../src/chunked_array/random.rs   | 25 ++++++++-----------
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/src/chunked_array/random.rs b/src/chunked_array/random.rs
index b78f0d83c..486040097 100644
--- a/src/chunked_array/random.rs
+++ b/src/chunked_array/random.rs
@@ -6,25 +6,22 @@ use rand::prelude::*;
 use rand::seq::IteratorRandom;
 use rand_distr::{Distribution, Normal, StandardNormal, Uniform};
 
-fn create_rand_index_with_replacement(n: usize, len: usize) -> (ThreadRng, UInt32Chunked) {
+fn create_rand_index_with_replacement(n: usize, len: usize) -> UInt32Chunked {
     let mut rng = rand::thread_rng();
-    (
-        rng,
-        (0u32..n as u32)
-            .map(move |_| Uniform::new(0u32, len as u32).sample(&mut rng))
-            .collect_trusted::<NoNull<UInt32Chunked>>()
-            .into_inner(),
-    )
+    (0u32..n as u32)
+        .map(move |_| Uniform::new(0u32, len as u32).sample(&mut rng))
+        .collect_trusted::<NoNull<UInt32Chunked>>()
+        .into_inner()
 }
 
-fn create_rand_index_no_replacement(n: usize, len: usize) -> (ThreadRng, UInt32Chunked) {
+fn create_rand_index_no_replacement(n: usize, len: usize) -> UInt32Chunked {
     // TODO! prevent allocation.
     let mut rng = rand::thread_rng();
     let mut buf = AlignedVec::with_capacity(n);
     // Safety: will be filled
     unsafe { buf.set_len(n) };
     (0u32..len as u32).choose_multiple_fill(&mut rng, buf.as_mut_slice());
-    (rng, UInt32Chunked::new_from_aligned_vec("", buf))
+    UInt32Chunked::new_from_aligned_vec("", buf)
 }
 
 impl<T> ChunkedArray<T>
@@ -42,13 +39,13 @@ where
 
         match with_replacement {
             true => {
-                let (_, idx) = create_rand_index_with_replacement(n, len);
+                let idx = create_rand_index_with_replacement(n, len);
                 // Safety we know that we never go out of bounds
                 debug_assert_eq!(len, self.len());
                 unsafe { Ok(self.take_unchecked((&idx).into())) }
             }
             false => {
-                let (_, idx) = create_rand_index_no_replacement(n, len);
+                let idx = create_rand_index_no_replacement(n, len);
                 // Safety we know that we never go out of bounds
                 debug_assert_eq!(len, self.len());
                 unsafe { Ok(self.take_unchecked((&idx).into())) }
@@ -73,8 +70,8 @@ impl DataFrame {
         }
         // all columns should used the same indices. So we first create the indices.
         let idx: UInt32Chunked = match with_replacement {
-            true => create_rand_index_with_replacement(n, self.height()).1,
-            false => create_rand_index_no_replacement(n, self.height()).1,
+            true => create_rand_index_with_replacement(n, self.height()),
+            false => create_rand_index_no_replacement(n, self.height()),
         };
         // Safety:
         // indices are within bounds

base-commit: dab34d3832935bb084c1ec583a729a261a6160b2
-- 
2.36.1

